package com.sam.demo.service;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.sam.demo.entity.User;
import com.sam.demo.repository.UserRepository;

@Service
public class UserService {

	@Autowired
	private UserRepository userRepository;

	public User findOne(Integer id) {
		return userRepository.findOne(id);
	}
	
	public List<User> findAll() {
		
		Iterable<User> iterable = userRepository.findAll();
		List<User> list = Lists.newArrayList(iterable);
		return list;
	}
	
	public Page<User> findByName(String name, Pageable pageable) {
		return userRepository.findByName(name, pageable);
	}
	
	public User saveOrUpdate(User user) {
		return userRepository.save(user);
	}
	
	public void delete(User user) {
		userRepository.delete(user);
	}
	
	public void deleteAll() {
		userRepository.deleteAll();
	}
}
